package me.spring.cloud.common.components.validator.annotation.constraint;

import me.spring.cloud.common.components.util.enums.TelPhoneEnum;
import me.spring.cloud.common.components.validator.annotation.TelPhone;
import me.spring.cloud.common.components.validator.util.RegularValidatorUtil;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 电话号码:手机or固话 验证
 * @author: luffy
 * @create: 2018-07-20 16:29
 **/
@Slf4j
public class TelPhoneValidator implements ConstraintValidator<TelPhone, String> {

  private TelPhoneEnum formatUnit;

  @Override
  public void initialize(TelPhone interf) {
    this.formatUnit = interf.formatUnit();
  }

  @Override
  public boolean isValid(String field, ConstraintValidatorContext cxt) {
    return RegularValidatorUtil.isValid(formatUnit, field);
  }
}